<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>物资盘点详情</title>
    <jsp:include page="/WEB-INF/view/commons/css.jsp" />
</head>
<body >
<div id="main-container" class="container-fluid">
    <input type="hidden" value="${checkId}" id="checkId">
    <button type="button" class="btn btn-primary" onclick="window.print()"><i class="fa fa-floppy-o"></i>&nbsp;打印</button>
    <div class="panel panel-info">
        <div class="panel-body" id="pop" style="text-align:center;">
        <%--<img src="http://127.0.0.1:8181/file/E2185E5F56534554B366CFABDAF10F54.png" hidden="hidden">--%>
        </div>
    </div><!-- /.panel -->
</div><!--/#main-container-->

<!-- script start -->
<jsp:include page="/WEB-INF/view/commons/js.jsp" />
<script src="${res}/static/plugin/pdfjs/pdf.js" type="text/javascript"></script>
<script type="text/javascript" src="${res}/static/plugin/jquery-print/jQuery.print.js"></script>
<script type="text/javascript">
    $(document).ready(function(e) {
        var id = $("#checkId").val();
        vm.showPdf(id);
    });
    var vm = this;
    //展示pdf文档
    vm.showPdf = function(id){
        vm.url = '${res}/file/'+id+'-signed.pdf';
        PDFJS.workerSrc = '${res}/static/plugin/pdfjs/pdf.worker.js';
        PDFJS.getDocument(vm.url).then(function getPdfHelloWorld(pdf) {
            vm.pdf = pdf;
            for (var i = 1; i <= pdf.numPages; i++) {
                var id = "canvas"+i;
                var html = "<canvas id='"+id+"' pagenum='"+i+"' style='width:100%;max-width: 890px;'></canvas>"
                $("#pop").append(html);
                vm.show(i);
            }
        });
    }
    vm.show = function(i){
        vm.pdf.getPage(i).then(function getPageHelloWorld(page) {
            var scale = 1.5;
            var viewport = page.getViewport(scale);
            var id = "canvas"+i;
            var canvas = document.getElementById(id);
            var context = canvas.getContext('2d');
            canvas.height = viewport.height-2;
            canvas.width = viewport.width-2;
            var renderContext = {
                canvasContext: context,
                viewport: viewport
            };
            page.render(renderContext);
        });
    }
    function submitInfo(){
        $.print("#pop1");
    }
</script>
<!-- script end -->
</body>
</html>
